package workSheets;

import java.util.Scanner;

public class workSheet1 {//you can choose metric or british,but it only can input metric

    public static void main(String[] args) throws Exception {
        user u = Factory.getInstance();//get a user
        info.set(u);//set information and output it
    }
}

class checkMain {
    public static boolean check(String s) {
        if (s.equalsIgnoreCase("B")) {
            return true;
        } else return s.equalsIgnoreCase("M");
    }

    @SuppressWarnings("all")
    public static boolean checkWight(String type, String s) {
        try {
            if (s.equalsIgnoreCase("quit")) {
                System.exit(0);
            }
            if (type.equalsIgnoreCase("mertic")) {
                double v = Double.parseDouble(s);
                if (v >= 500 || v <= 40) {
                    return false;
                } else {
                    return true;
                }
            } else {
                double v = Double.parseDouble(s);
                if (v >= 1100 || v <= 88) {
                    return false;
                } else {
                    return true;
                }
            }
        } catch (Exception e) {
            return false;
        }
    }

    @SuppressWarnings("all")
    public static boolean checkHeight(String type, String s) {
        try {
            if (s.equalsIgnoreCase("quit")) {
                System.exit(0);
            }
            if (type.equalsIgnoreCase("inch")) {
                double height = Double.parseDouble(s);
                if (height >= 10 || height <= 3) {
                    return false;
                } else {
                    return true;
                }
            }
            if (type.equalsIgnoreCase("foot")) {
                double height = Double.parseDouble(s);
                if (height >= 120 || height <= 40) {
                    return false;
                } else {
                    return true;
                }

            } else {
                double height = Double.parseDouble(s);
                if (height >= 300 || height <= 100) {
                    return false;
                } else {
                    return true;
                }
            }
        } catch (Exception e) {
            return false;
        }
    }

    public static void checkBMI(double weight, double height) {
        double BMI = weight / ((height * 0.01) * (height * 0.01));
        System.out.println("your BMI is  " + Math.round(BMI));
        System.out.println("Analysis........");
        if (BMI >= 18.5 && BMI <= 23.9) {
            System.out.println("your body is so good");
        } else if (BMI < 18.5) {
            System.out.println("your body is too thin");
        } else if (BMI > 23.9 && BMI <= 27.9) {
            System.out.println("your body is a little fat");
        } else {
            System.out.println("your body is too fat");
        }
    }
}

@SuppressWarnings("all")
class British {
    public static double tranPound(String s) {
        double v = 0;
        try {
            v = Double.parseDouble(s);
        } catch (Exception e) {
            System.out.println("error");
        }
        return v * 0.45;
    }

    public static double tranHeight(String s, double D) {
        if (s.equalsIgnoreCase("foot")) {
            return D * 2.54;
        } else if (s.equalsIgnoreCase("inch")) {
            return D * 30.48;
        } else {
            System.out.println("input type error");
            return 0;
        }
    }
}

class Metric {
    public static double trans(String s) {
        double D = 0;
        try {
            D = Double.parseDouble(s);
        } catch (Exception e) {
            System.out.println("input error");
        }
        return D;
    }


}

class Factory {
    private Factory() {
    }

    private user user;

    public static user getInstance() throws Exception {
        return (user) workSheets.user.class.getDeclaredConstructor().newInstance();
    }
}


class info {
    private user user;

    public static void set(user u) {
        Scanner scan = new Scanner(System.in);
        String s = "";
        while (!checkMain.check(s)) {
            System.out.println("input Your System(B/M):");
            s = scan.nextLine();
        }
        if (s.equalsIgnoreCase("b")) {
            String weight = "";
            String wType = "british";
            while (!checkMain.checkWight(wType, weight)) {
                System.out.println("input your  weight");
                weight = scan.nextLine();
            }
            System.out.println("input your British height Type");
            String type = new Scanner(System.in).nextLine();
            while (!(type.equalsIgnoreCase("foot") || type.equalsIgnoreCase("inch"))) {
                System.out.println("input your British height Type again");
                type = new Scanner(System.in).nextLine();
            }
            System.out.println("input your height");
            String height = scan.nextLine();
            while (!checkMain.checkHeight(type, height)) {
                System.out.println("input your right height");
                height = scan.nextLine();
            }
            System.out.println("output your info by mertic T/F");
            String a = new Scanner(System.in).nextLine();
            if (a.equalsIgnoreCase("T")) {
                u.setHigh(British.tranHeight(type, Double.parseDouble(height)));
                u.setWeight(British.tranPound(weight));
                System.out.println("your weight is  " + u.getWeight() + "kg\n" + "your Height is  " + u.getHigh() + "cm");
                checkMain.checkBMI(u.getWeight(), u.getHigh());
            } else {
                u.setWeight(Double.parseDouble(weight));
                u.setHigh(Double.parseDouble(height));
                if (type.equalsIgnoreCase("foot")) {
                    System.out.println("your weight is  " + u.getWeight() + "lb\n" + "your Height is  " + u.getHigh() + "ft");
                }
                if (type.equalsIgnoreCase("inch")) {
                    System.out.println("your weight is  " + u.getWeight() + "lb\n" + "your Height is  " + u.getHigh() + "in");
                }
                u.setHigh(British.tranHeight(type, Double.parseDouble(height)));
                u.setWeight(British.tranPound(weight));
                checkMain.checkBMI(u.getWeight(), u.getHigh());
            }

        } else {
            System.out.println("input your weight");
            String weight = scan.nextLine();
            String type = "mertic";
            while (!checkMain.checkWight(type, weight)) {
                System.out.println("input your right weight");
                weight = scan.nextLine();
            }
            u.setWeight(Metric.trans(weight));
            System.out.println("input your height");
            String height = scan.nextLine();
            while (!checkMain.checkHeight(type, height)) {
                System.out.println("input your right height");
                height = scan.nextLine();
            }
            u.setHigh(Metric.trans(height));
            System.out.println("your weight is  " + u.getWeight() + "kg\n" + "your Height is  " + u.getHigh() + "cm");
            checkMain.checkBMI(u.getWeight(), u.getHigh());
        }
    }
}

class user {
    private double weight;
    private double high;

    public user() {
    }

    public user(double weight, double high) {
        this.weight = weight;
        this.high = high;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public double getHigh() {
        return high;
    }

    public void setHigh(double high) {
        this.high = high;
    }
}